package com.bt.springboot.demo;

import com.bt.springboot.entity.Person;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * @author zkx
 * @Date 2023/11/28 18:38
 */
public class StreamDemo {

	public static void main(String[] args) {
		List<Person> personList = new ArrayList<>();
		personList.add(new Person(1L,"张三",20,"13812345678",1L,"张三","研发部","研发中心"));
		personList.add(new Person(2L,"李四",18,"13812345678",1L,"李四","研发部","研发中心"));
		personList.add(new Person(3L,"王五",22,"13812345678",1L,"王五","研发部","研发中心"));
		steamSortAsc(personList);
		System.out.println("-------");
		steamSortDesc(personList);
	}

	/**
	 * 按照年龄正序排序
	 */
	public static void steamSortAsc(List<Person> list){
		list.stream().sorted(Comparator.comparing(Person::getAge)).forEach(System.out::println);
	}

	/**
	 * 按照年龄倒序排序
	 * @param list
	 */
	public static void steamSortDesc(List<Person> list){
		list.stream().sorted(Comparator.comparing(Person::getAge).reversed()).forEach(System.out::println);
	}

}
